package cn.s1995.sloth.bizs.entity;

import cn.s1995.sloth.bizs.entity.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;

/**
 * API日志
 *
 * @author Lex
 * @date 2024-05-18 07:02:13
 */
@Data
@Accessors(chain = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(description = "API日志")
@TableName("biz_api_log")
public class ApiLog extends BaseEntity {


	/**
	* ID
	*/
    @TableId(type = IdType.ASSIGN_ID)
    @Schema(description = "ID")
    private Long id;

	/**
	* 请求uri
	*/
    @Schema(description = "请求uri")
    private String uri;

	/**
	* 请求方式
	*/
    @Schema(description = "请求方式")
    private String method;

	/**
	* 请求头
	*/
    @Schema(description = "请求头")
    private String headers;

	/**
	* 请求参数-query
	*/
    @Schema(description = "请求参数-query")
    private String query;

	/**
	* 请求参数-body
	*/
    @Schema(description = "请求参数-body")
    private String body;

	/**
	* 响应参数
	*/
    @Schema(description = "响应参数")
    private String response;

	/**
	* ip
	*/
    @Schema(description = "ip")
    private String ip;

	/**
	* 开始时间
	*/
    @Schema(description = "开始时间")
    private String beginDate;

	/**
	* 结束时间
	*/
    @Schema(description = "结束时间")
    private String endDate;

	/**
	* 耗时(ms)
	*/
    @Schema(description = "耗时(ms)")
    private String elapsedTime;

	public String format() {
		return
				"\n/************************************************************************************\n" +
						"method: " + this.method + " uri: " + this.uri + " ip: [" + this.ip + "]\n" +
						"headers: " + this.headers + "\n" +
						"queryString: " + this.query + "\n" +
						"body: " + this.body + "\n" +
						"response: " + this.response + "\n" +
						"range time: [" + this.beginDate + " ~ " + this.endDate + "] elapsed time: [" + this.elapsedTime + "]\n" +
						"************************************************************************************/\n";
	}
}
